home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / PROGRAMMING / DESKLIBC / SOURCES.ZIP / DeskLib / !DLSources / Libraries / DragASpr / s / DragIcon next >
Text File  |  1995-08-26  |  4KB  |  125 lines

  1. ; Copyright 1993 Shaun Blackmore and Jason Williams
  2. ; (Shaun wrote the C version, plus the basis of this assembler, which I then
  3. ;  got working correctly and added the CMOS check into)
  4. ; version 1.01
  5. ;
  6. ; Interestingly, this code is only about 4 instructions shorter than its
  7. ; C code equivalent.
  8. ;
  9. ; Updates
  10. ; 1.01 JW  Fixed this code so it now works under RISC OS 2. Took me ages to
  11. ;          find out that it was passing &ffffffff instead of &7fffffff into
  12. ;          wimp_dragbox (that works under RO3 but not under RO2!)
  13. ;          (that meant the dragbox was limited to a rectangle between -1 and 0
  14. ;          rather than to the entire screen extent)
  15.  
  16.  
  17.         GET     ^.h.regdefs
  18.         GET     ^.h.swinos
  19.         GET     ^.h.macros
  20.  
  21. ; void DragASprite_DragIcon(window_handle window, icon_handle icon);
  22.  
  23.         PREAMBLE
  24.         STARTCODE DragASprite_DragIcon
  25. ;
  26.         STMFD   sp!, {r4,r5,r6,r7,lr}
  27.         MOV     ip,sp
  28.  
  29.         SUB     sp, sp, #40        ; Set up block for GetWindowState
  30.         STR     r0, [sp, #0]       ; icon.window=r0
  31.  
  32.         MOV     r7, r1             ; remember icon number for later...
  33.           MOV     r1, sp           ; r1 = pointer to windowstate block
  34.  
  35.           SWI     SWI_Wimp_GetWindowState + XOS_Bit
  36.           BVS     Exit
  37.  
  38.           LDR     r2, [sp, #4]
  39.           LDR     r3, [sp, #20]
  40.           SUB     r2, r2, r3       ; r2 = window_origin_x
  41.  
  42.           LDR     r3, [sp, #16]
  43.           LDR     r4, [sp, #24]
  44.           SUB     r3, r3, r4       ; r3 = window_origin_y
  45.  
  46.                                    ; Set up a DragBox structure
  47.           SUB     sp, sp, #40      ; Drag Structure
  48.  
  49.           STR     r0, [sp, #0]     ; drag.window=r0
  50.           MOV     r0, #5
  51.           STR     r0, [sp, #4]     ; drag.type=5;
  52.  
  53.                                    ; Now get the icon state
  54.         STR     r7, [r1, #4]       ; store icon- Block already has windowhandle
  55.         SWI     SWI_Wimp_GetIconState + XOS_Bit
  56.         BVS     Exit
  57.  
  58.         ADD     r1, r1, #8         ; r1 = icon block
  59.                                    ; sp = drag structure
  60.         LDMIA   r1,{r4,r5,r6,r7}   ; Read icon bounding rectangle
  61.  
  62.           ADD     r4, r4, r2       ; Convert offsets from window origin (TL)
  63.           ADD     r5, r5, r3       ; into absolute screen coordinates, using
  64.           ADD     r6, r6, r2       ; the window origin calculated above (r2,r3)
  65.           ADD     r7, r7, r3
  66.  
  67.         ADD     r2, sp, #8         ; r1 = bounding box
  68.         STMIA   r2,{r4,r5,r6,r7}
  69.  
  70.         MOV     r0,#0
  71.         STR     r0,[sp,#24]        ; parent.x0 = 0
  72.         STR     r0,[sp,#28]        ; parent.y0 = 0
  73.  
  74.         LDR     r0, VeryBig
  75.         STR     r0,[sp,#32]        ; parent.x1 = &7FFFFFFF
  76.         STR     r0,[sp,#36]        ; parent.y1 = &7FFFFFFF
  77.  
  78.         MOV     r7, r1             ; r7 = pointer to icon state data
  79.  
  80.                                    ; Check if DragASprite is available
  81.         ADD     r1, pc, #DragString-.-8
  82.         SWI     SWI_OS_SWINumberFromString + XOS_Bit
  83.         BVS     NoDrag             ; It isn't, so do Wimp_DragBox
  84.  
  85.         MOV     r0, #161           ; Check the DragASpr configuration bit
  86.         MOV     r1, #28
  87.         SWI     SWI_OS_Byte + XOS_Bit
  88.         TST     r2, #2             ; Is DragASprite enabled?
  89.         BEQ     NoDrag             ; No - do a Wimp_DragBox
  90.  
  91.         LDR     r0, [r7, #16]      ; check for icon type - is it indirected?
  92.         TST     r0, #256
  93.                                    ; Not Indirected
  94.         MOVEQ   r1, #1             ;   System area
  95.         ADDEQ   r2, r7, #20        ;   Point to data
  96.  
  97.         LDRNE   r1, [r7, #24]      ; Is Indirected
  98.         LDRNE   r2, [r7, #20]      ;
  99.  
  100.         ADD     r3, sp, #8         ; r3 => Bounding box
  101.         ADD     r4, sp, #24        ; r4 => Parent box (not actually needed)
  102.  
  103.         MOV     r0, #197           ; Flags- centered, bbox = screen bounds,
  104.                                    ; bbox limits mouse pointer, has drop shadow
  105.  
  106.         SWI     SWI_DragASprite_Start + XOS_Bit
  107.         B       Exit
  108.  
  109. NoDrag
  110.         MOV     r1, sp             ; Can't DragASprite, so Wimp_DragBox instead
  111.         SWI     SWI_Wimp_DragBox + XOS_Bit
  112.  
  113. Exit
  114.         MOV     sp, ip             ; restore old stack pointer
  115.         MOVVC   r0, #0
  116.         LDMFD   sp!, {r4,r5,r6,r7,pc}^
  117. ;
  118. VeryBig
  119.         DCD     &7fffffff
  120. ;
  121. DragString
  122.         DCB     "DragASprite_Start",0
  123.  
  124.         END
  125.